# 输入：文件路径
# 输出：vtkActor
import vtkmodules.all as vtk


class IGltfReader():
    v_reader = vtk.vtkGLTFReader()
    v_actor = vtk.vtkActor()
    v_mapper = vtk.vtkDataSetMapper()
    v_clean_filter = vtk.vtkCleanPolyData()
    v_poly_filter = vtk.vtkCompositeDataGeometryFilter()

    def __init__(self, options=None):
        self._initMapper()

        self.v_actor.SetMapper(self.v_mapper)

    def _initMapper(self):
        self.v_clean_filter.SetInputConnection(self.v_reader.GetOutputPort())
        self.v_poly_filter.SetInputConnection(self.v_clean_filter.GetOutputPort())
        self.v_mapper.SetInputConnection(self.v_poly_filter.GetOutputPort())

    def SetFileName(self, file_path, force_update=False):
        self.v_reader.SetFileName(file_path)
        if (force_update):
            self.Update()

    def Update(self):
        self.v_reader.Update()
        self.v_clean_filter.Update()
        self.v_poly_filter.Update()

    def GetActor(self):
        return self.v_actor
